//
//  PGVisitorTableViewController.swift
//  PGWeibo
//
//  Created by Apple on 15/11/3.
//  Copyright © 2015年 Apple. All rights reserved.
//

import UIKit

class PGVisitorTableViewController: UITableViewController {
    /// 记录用户是否登录
    var userLogon = PGUserAccountViewModel.sharedUerAccountViewModel.userLogon
    
    /// 访客视图
    var visitorView: PGVisitor?
    
    override func loadView() {
        
            userLogon ? super.loadView() : loadVisitorView()
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        //添加监听
        visitorView?.regisetButton.addTarget(self, action: "visitorLoginViewDidRegister", forControlEvents: .TouchUpInside)
        visitorView?.loginButton.addTarget(self, action: "visitorLoginViewDidLogin", forControlEvents: .TouchUpInside)
        

    }
    
    private func loadVisitorView() {
        //添加导航栏按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "visitorLoginViewDidRegister")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: "visitorLoginViewDidLogin")
        visitorView = PGVisitor()
        view = visitorView
    }
}
// MARK: - 用户登录注册监听时间
extension PGVisitorTableViewController {
    func visitorLoginViewDidLogin() {
        let vc = PGOAuthViewController()
        let nav = UINavigationController(rootViewController: vc)
        presentViewController(nav, animated: true, completion: nil)
    }
    func visitorLoginViewDidRegister() {
        print("用户注册")
    }
}